Skip to content

try to make rustc-dev work with and without LTO - #161535

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:aarch64-lto-compat
Open

try to make rustc-dev work with and without LTO#161535
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:aarch64-lto-compat

Conversation

@RalfJung

@RalfJung RalfJung commented Aug 22, 2026

Copy link
Copy Markdown
Member

View all comments

This might fix the issues introduced by #161260.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 22, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=dist*linux

rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
try to make rustc-dev work with and without LTO


try-job: dist*linux
@rust-bors

This comment has been minimized.

@weihanglo

Copy link
Copy Markdown
Member

try jobs=dist*linux

TIL glob is supported.

// Compiling C deps, like jemalloc and llvm-wrapper, should be with
// the same LTO mode as the Rust code they are linked into.
// Compiling C deps, like jemalloc and llvm-wrapper, should be with the same LTO mode as
// the Rust code they are linked into. We don't pass the checks cc-rs uses to

@Zoxc Zoxc Aug 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be with the same LTO mode as the Rust code they are linked into
Just a note that this doesn't seem very true.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the discussion happens in #t-compiler > Analysing broken jemalloc rlib

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that this doesn't seem very true.

I just reformatted that comment, I don't know if it is correct.
What would be more correct?

@weihanglo

weihanglo commented Aug 22, 2026

Copy link
Copy Markdown
Member

Should we do something like this after the let lto_flags = ...?

            if lto_cflag.is_some()
                && builder.config.bootstrap_override_lld.is_used()
                && !target.is_msvc()
            {
                self.rustflags.arg("-Clink-args=-Wl,--fat-lto-objects");
            }

I am testing dist build on my machine still though.

@rust-bors

rust-bors Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a4edfb9 (a4edfb99457ab3be0979b69702c5a12bb7d12269)
Base parent: b0ca9c7 (b0ca9c712455d865c3bf0bf5325a3e79677a2d97)

@weihanglo

Copy link
Copy Markdown
Member

I guess we want a perf build

@rust-timer build a4edfb9

@rust-timer

This comment has been minimized.

@RalfJung

Copy link
Copy Markdown
Member Author

Should we do something like this after the let lto_flags = ...?

I have no idea.

@rust-timer

This comment was marked as outdated.

@rustbot rustbot added the perf-regression Performance regression. label Aug 22, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

This did fix Miri but I guess it also broke LTO. I'll try the magic linker incantation you mentioned above then.

@RalfJung
RalfJung force-pushed the aarch64-lto-compat branch from 8975695 to d2077da Compare August 22, 2026 21:32
@RalfJung

Copy link
Copy Markdown
Member Author

@bors try jobs=dist*linux
@rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 22, 2026
try to make rustc-dev work with and without LTO


try-job: dist*linux
Comment thread src/bootstrap/src/core/builder/cargo.rs Outdated
// Make sure the linker actually uses the fat LTO part.
if lto_cflag.is_some()
&& builder.config.bootstrap_override_lld.is_used()
&& !target.is_msvc()

@RalfJung RalfJung Aug 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I don't understand why we need to check for MSVC here, given that above we already check for clang.

Also, when does it ever make sense to set -ffat-lto-objects without setting the link-args as well?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC clang-cl.exe still produces COFF object, right? So even it is clang-like we should not pass that link arg, as it is not supported yet.

https://llvm.org/docs/FatLTO.html#supported-file-formats

Or alternativelu we should just apply to x86_64 Linux as we previously discussed.

@weihanglo weihanglo Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://releases.llvm.org/22.1.0/tools/lld/docs/ReleaseNotes.html#coff-improvements

Oh! In LLVM 22 COFF gains the support of fat LTO.
Though according to bjorn3 we are still on 21 right now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when does it ever make sense to set -ffat-lto-objects without setting the link-args as well?

And yeah it probably makes little sense. We may be able to just figure out the minimal condition and coerce them in one of block

@weihanglo weihanglo Aug 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the entire code can be simplified to this?

let lto_cflag = if matches!(self.mode, Mode::Rustc | Mode::ToolRustcPrivate)
    && is_lto_stage(&self.compiler)
    && builder.cc_tool(target).is_like_clang()
    && builder.config.bootstrap_override_lld.is_used() // unsure if we should take care of non-dist config for downstream packagers
{

    let lto_cflag = match builder.config.rust_lto {
        RustcLto::Thin => Some("-flto=thin -ffat-lto-objects"),
        RustcLto::Fat => Some("-flto=full -ffat-lto-objects"),
        RustcLto::ThinLocal | RustcLto::Off => None,
    };

    if lto_cflag.is_some() {
        self.rustflags.arg("-Clink-args=-Wl,--fat-lto-objects");
    }
    lto_cflag
} else {
    None
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied that, and it seems to work. 🤷

@weihanglo

Copy link
Copy Markdown
Member

So I got a result of libtikv_jemalloc_sys.rlib size on aarch64

  • native (pre PR 161260, c656540): 4.81 MB
  • bitcode only (PR 161260, 124c16e): 4.84 MB
  • fat LTO object (this PR, d2077da): 9.54 MB

All above are uncompressed size.

@rust-bors

rust-bors Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 5db500f (5db500f538a1f4727c942992cbc3d05b437d5930)
Base parent: 78c04b6 (78c04b6a348438fb9396b8864cd34f92fb99cd53)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5db500f): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (secondary -8.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-12.7% [-13.0%, -12.4%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.0%, secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 5
Improvements ✅
(secondary)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 5

Bootstrap: 468.574s -> 466.803s (-0.38%)
Artifact size: 400.20 MiB -> 400.15 MiB (-0.01%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Aug 23, 2026
@weihanglo

Copy link
Copy Markdown
Member

And for x86_64 uncompressed libtikv_jemalloc_sys.rlib:

  • no native state
  • bitcode only (PR 161260, 124c16e): 4.82 MB
  • fat LTO (this PR trybuild, 5db500f): 9.41 MB

@RalfJung

RalfJung commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

On aarch64-linux, the rustc-dev component went from 125 MiB to 128 MiB.
On x86-64-linux, it went from 142 MiB to 143 MiB.

That seems fine? That's compressed size obviously though, so this may consume a lot more disk space if it compresses very well. If I check locally the whole folder lib/rustlib/x86_64-unknown-linux-gnu/lib it went from 773 MiB to 777 MiB... looks like that tikv file is the only file that got bigger.^^

@RalfJung

Copy link
Copy Markdown
Member Author

Yeah I think this should be ready now. I don't actually understand why the conditions are how they are, I just copied that from @weihanglo. ;) I kicked off another perf run to be sure but that last reorganization shouldn't change anything.

r? @Kobzol

@rustbot rustbot assigned Kobzol and unassigned jieyouxu Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Kobzol is not on the review rotation at the moment.
They may take a while to respond.

@RalfJung RalfJung added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 23, 2026

@weihanglo weihanglo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as I introduced the regression and proposed the change :D

View changes since this review

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a259cfd): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary 3.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.1%, secondary -2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) -2.1% [-2.1%, -2.1%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 469.531s -> 468.171s (-0.29%)
Artifact size: 400.26 MiB -> 400.30 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 23, 2026
Comment thread src/bootstrap/src/core/builder/cargo.rs Outdated
&& is_lto_stage(&self.compiler)
&& builder.cc_tool(target).is_like_clang()
// unsure if we should take care of non-dist config for downstream packagers
&& builder.config.bootstrap_override_lld.is_used()

@Kobzol Kobzol Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this config is only used for speeding up the build process itself, and it should in fact be completely unnecessary on x64 now, to the point where we should remove it from its CI config.

Why is this condition needed? Isn't the whole point of the config below that the resulting code will be compilable even without LLD?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally fine with removing it, all these conditions are a mystery to me. ;)

@RalfJung
RalfJung force-pushed the aarch64-lto-compat branch from 60ea0f4 to 85cc84f Compare August 24, 2026 06:34
@Kobzol

Kobzol commented Aug 24, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 24, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
try to make rustc-dev work with and without LTO
};
// Make sure the linker actually uses the fat LTO part.
if lto_cflag.is_some() {
self.rustflags.arg("-Clink-args=-Wl,--fat-lto-objects");

@RalfJung RalfJung Aug 24, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this flag is needed to make the linker even recognize the bitcode in fat LTO objects. It is strange that this is not the default (unlike LTO for "thin" objects which apparently is the default). Does this mean we're also not LTO'ing jemalloc for the distributed Miri, Clippy etc any more?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do a Clippy benchmark after the current one finishes to check.

@rust-bors

rust-bors Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0ff57e8 (0ff57e8a1e520723d1162f33201a36e14c9db339)
Base parent: da51146 (da5114692c9ebe46b869488c5f34f92eb10b98c1)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0ff57e8): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary 7.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.5% [7.5%, 7.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.4%, secondary -0.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.5% [6.5%, 6.5%] 1
Improvements ✅
(primary)
-2.4% [-2.4%, -2.4%] 1
Improvements ✅
(secondary)
-3.4% [-4.6%, -2.3%] 3
All ❌✅ (primary) -2.4% [-2.4%, -2.4%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 469.244s -> 471.258s (0.43%)
Artifact size: 400.19 MiB -> 400.31 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 24, 2026
@Kobzol

Kobzol commented Aug 24, 2026

Copy link
Copy Markdown
Member

@bors try jobs=dist-x86_64-linux profiles=clippy

@rust-bors

This comment was marked as outdated.

@Kobzol

Kobzol commented Aug 24, 2026

Copy link
Copy Markdown
Member

@bors try jobs=dist-x86_64-linux @rust-timer queue profiles=clippy

@rust-timer

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 24, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
try to make rustc-dev work with and without LTO


try-job: dist-x86_64-linux
@rust-bors

rust-bors Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 85c799e (85c799e5714eeb9d5b29f2e950896cf34d26f2c3)
Base parent: 04a3cad (04a3cad16c522be4fd15ca76d3c119c14be68954)

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued 85c799e with parent 04a3cad, future comparison URL.
There is currently 1 preceding artifact in the queue.
It will probably take at least ~1.4 hours until the benchmark run finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: Our Github Actions CI A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants